home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / zfont2.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.5 KB  |  118 lines

  1. /* Copyright (C) 1991, 1995, 1996, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: zfont2.c,v 1.3 2000/09/19 19:00:53 lpd Exp $ */
  20. /* Type 2 font creation operators */
  21. #include "ghost.h"
  22. #include "oper.h"
  23. #include "gxfixed.h"
  24. #include "gsmatrix.h"
  25. #include "gxfont.h"
  26. #include "gxfont1.h"
  27. #include "bfont.h"
  28. #include "idict.h"
  29. #include "idparam.h"
  30. #include "ifont1.h"
  31. #include "ifont2.h"
  32.  
  33. /* Private utilities */
  34. private uint
  35. subr_bias(const ref * psubrs)
  36. {
  37.     uint size = r_size(psubrs);
  38.  
  39.     return (size < 1240 ? 107 : size < 33900 ? 1131 : 32768);
  40. }
  41.  
  42. /*
  43.  * Get the additional parameters for a Type 2 font (or FontType 2 FDArray
  44.  * entry in a CIDFontType 0 font), beyond those common to Type 1 and Type 2
  45.  * fonts.
  46.  */
  47. int
  48. type2_font_params(const_os_ptr op, charstring_font_refs_t *pfr,
  49.           gs_type1_data *pdata1)
  50. {
  51.     int code;
  52.     float dwx, nwx;
  53.  
  54.     pdata1->interpret = gs_type2_interpret;
  55.     pdata1->lenIV = DEFAULT_LENIV_2;
  56.     pdata1->subroutineNumberBias = subr_bias(pfr->Subrs);
  57.     /* Get information specific to Type 2 fonts. */
  58.     if (dict_find_string(pfr->Private, "GlobalSubrs", &pfr->GlobalSubrs) > 0) {
  59.     if (!r_is_array(pfr->GlobalSubrs))
  60.         return_error(e_typecheck);
  61.     }
  62.     pdata1->gsubrNumberBias = subr_bias(pfr->GlobalSubrs);
  63.     if ((code = dict_uint_param(pfr->Private, "gsubrNumberBias",
  64.                 0, max_uint, pdata1->gsubrNumberBias,
  65.                 &pdata1->gsubrNumberBias)) < 0 ||
  66.     (code = dict_float_param(pfr->Private, "defaultWidthX", 0.0,
  67.                  &dwx)) < 0 ||
  68.     (code = dict_float_param(pfr->Private, "nominalWidthX", 0.0,
  69.                  &nwx)) < 0
  70.     )
  71.     return code;
  72.     pdata1->defaultWidthX = float2fixed(dwx);
  73.     pdata1->nominalWidthX = float2fixed(nwx);
  74.     {
  75.     ref *pirs;
  76.  
  77.     if (dict_find_string(pfr->Private, "initialRandomSeed", &pirs) <= 0)
  78.         pdata1->initialRandomSeed = 0;
  79.     else if (!r_has_type(pirs, t_integer))
  80.         return_error(e_typecheck);
  81.     else
  82.         pdata1->initialRandomSeed = pirs->value.intval;
  83.     }
  84.     return 0;
  85. }
  86.  
  87. /* <string|name> <font_dict> .buildfont2 <string|name> <font> */
  88. /* Build a type 2 (compact Adobe encrypted) font. */
  89. private int
  90. zbuildfont2(i_ctx_t *i_ctx_p)
  91. {
  92.     os_ptr op = osp;
  93.     charstring_font_refs_t refs;
  94.     build_proc_refs build;
  95.     int code = build_proc_name_refs(&build,
  96.                     "%Type2BuildChar", "%Type2BuildGlyph");
  97.     gs_type1_data data1;
  98.  
  99.     if (code < 0)
  100.     return code;
  101.     code = charstring_font_get_refs(op, &refs);
  102.     if (code < 0)
  103.     return code;
  104.     code = type2_font_params(op, &refs, &data1);
  105.     if (code < 0)
  106.     return code;
  107.     return build_charstring_font(i_ctx_p, op, &build, ft_encrypted2, &refs,
  108.                  &data1, bf_notdef_required);
  109. }
  110.  
  111. /* ------ Initialization procedure ------ */
  112.  
  113. const op_def zfont2_op_defs[] =
  114. {
  115.     {"2.buildfont2", zbuildfont2},
  116.     op_def_end(0)
  117. };
  118.